import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class BubbleDemoPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return BubbleDemoPageState();
  }
}

class BubbleDemoPageState extends State<BubbleDemoPage> {
  final bubbleHeight = 60;
  final bubbleWidth =120;

  GlobalKey key1 = GlobalKey();

  getX(GlobalKey key) {
    RenderBox renderBox = key.currentContext.findRenderObject();
    double x = renderBox.localToGlobal(Offset.zero).dx;
    return x;
  }

  getY(GlobalKey key) {
    RenderBox renderBox = key.currentContext.findRenderObject();
    double y = renderBox.localToGlobal(Offset.zero).dy;
    return y;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('绝对定位例子')),
      body: Container(
        height: MediaQuery.of(context).size.height,
        width: MediaQuery.of(context).size.width,
        margin: EdgeInsets.all(10),
        child: Stack(
          children: <Widget>[
            MaterialButton(
              key: key1,
              onPressed: () {

              },
              color: Colors.blue,
            ),
            Positioned(
              child: MaterialButton(
                onPressed: () {},
                color: Colors.yellow,
              ),
              left: MediaQuery.of(context).size.width / 2,
              top: MediaQuery.of(context).size.height / 2,
            )
          ],
        ),
      ),
    );
  }
}
